今天,我們就來簡單的撰寫一份 Dockerfile 吧 !
首先,建立存放 Dockerfile 的資料夾
jiahong@ubuntu:~$ mkdir Dockerfile
jiahong@ubuntu:~$ ls
Dockerfile
jiahong@ubuntu:~$ cd Dockerfile/
jiahong@ubuntu:~/Dockerfile$
撰寫 Dockerfile 檔案
FROM ubuntu:16.04
MAINTAINER jiahong
RUN apt-get update -y \
&& apt-get install nginx -y
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
然後在此資料夾底下 build Dockerfile
root@ubuntu:~/Dockerfile# docker build -t nginx-build .
Sending build context to Docker daemon 2.048kB
Step 1/5 : FROM ubuntu:16.04
---> 00fd29ccc6f1
Step 2/5 : MAINTAINER jiahong
---> Using cache
---> 8055eef138ab
Step 3/5 : RUN apt-get update -y && apt-get install nginx -y
---> Using cache
---> 6e012b0ec790
Step 4/5 : EXPOSE 8080
---> Using cache
---> 057166eb2723
Step 5/5 : CMD nginx -g daemon off;
---> Running in e7a4d85552ed
---> f572a21fe40e
Removing intermediate container e7a4d85552ed
Successfully built f572a21fe40e
Successfully tagged nginx-build:latest
執行 Container 並觀看 Container 是否被正確啟動
root@ubuntu:~/Dockerfile# docker run -itd --name nginx -p 8080:80 nginx-build
b8f85bfbde678429a1bf13666b3520527f275e84e677bb5fbf8935f09d93176e
root@ubuntu:~/Dockerfile# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b8f85bfbde67 nginx-build "nginx -g 'daemon ..." 4 seconds ago Up 3 seconds 0.0.0.0:8080->80/tcp nginx
這樣打
就有 nginx 的預設頁面了
那今天就先到這吧 ~